import { createApp, h } from "vue";

import App from "./App.vue";

import { createWebHashHistory, createRouter } from "vue-router";

import User from "./views/User.vue";
import Home from "./views/Home.vue";
import Login from "./views/Login.vue";
import Shop from "./views/Shop.vue";
import Body from "./views/Body.vue";
import Header from "./views/Header.vue";

localStorage.token = "";
const router = createRouter({
  history: createWebHashHistory(),
  routes: [
    {
      path: "/",
      redirect: "/home",
    },
    {
      path: "/h",
      alias: "/home/a/b/c/d",
      component: Home,
    },
    {
      path: "/home",
      component: Home,
      children: [
        { path: "body", name: "home-body", alias: "/b", component: Body },
        {
          path: "Header",
          component: Header,
        },
      ],
    },
    {
      path: "/shop",
      redirect: "/home",
      component: Shop,
      children: [],
    },
    {
      path: "/login",
      name: "login",
      component: Login,
    },
    {
      path: "/user",
      // redirect: "/login",
      // redirect: {
      //   // path: "/login",
      //   name: "login",
      // },
      redirect(to) {
        // user route
        // console.log(to);
        // return "/login";
        if (!localStorage.token) {
          return { name: "login" };
        }
        return "/";
      },
      // component: User,
    },
  ],
});

const app = createApp({ render: () => h(App) });

app.use(router);

app.mount("#app");
